***Replication for Do Parties affect economic inequality***
*Perspectives on Politics
*Martin Haselmayer, Alexander Horn
*Stata 18
*Version 1.0 (8/29/2024)

log using PoP_replication, replace

version 18.0
set more off
clear mata

*1) Set working directories
global DATADIR  "SET YOUR DATA DIRECTORY" 
global GRAPHDIR "SET YOUR GRAPH DIRECTORY"
global RESULTSDIR "SET YOUR GRAPH DIRECTORY"

*1) Load data
cd  "$DATADIR"
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

*2) Descriptive analyses:

*2a) Results reported in the discussion
tab paper_id

egen paper_gr=group(paper_id) 
su paper_gr //43 unique papers

bysort paper_gr: gen paper_count=_N 
su paper_count


*Results per study: count/study
bysort paper_gr: gen paper_nvals=_n if partyeffect!=.
su paper_gr
su paper_nvals
egen modelid=group(id_models)
su modelid


*Year
tab year if paper_nvals==1
su year if paper_nvals==1 & partyeffect!=.,d

*Journals
tab journal if paper_nvals==1, sort

*Partisan effect
su partyeffect //37-63
tab partyeffect party_control, col //no-yes: DV: 53-47 vs. Control: 70-30

*Time effects
su goldenshare


**Fig. 1: Time periods and partisan effects on inequality
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

xtile pct_goldenshare = goldenshare, nq(4)
bysort pct_goldenshare: su goldenshare

**Coefficient of variation:
forval i=1(1)5 {
	summarize partyeffect if pct_goldenshare==`i'
di 100 * r(sd) / r(mean) 	
}	

ttest partyeffect if pct_goldenshare==1 | pct_goldenshare==4, by(pct_goldenshare) //sign at 0.001
ttest partyeffect if pct_goldenshare==2 | pct_goldenshare==4, by(pct_goldenshare) // sign. at 0.001
ttest partyeffect if pct_goldenshare==3 | pct_goldenshare==4, by(pct_goldenshare) // sign. at 0.1
bysort  pct_goldenshare: su goldenshare

collapse (mean) meanvar= partyeffect (sd) sdwrite=partyeffect  (count) n=partyeffect , by(pct_goldenshare)

* upper and lower values of the confidence interval.
    generate hivar = meanvar + invttail(n-1,0.05)*(sdwrite / sqrt(n))
    generate lowar = meanvar - invttail(n-1,0.05)*(sdwrite / sqrt(n))
	replace lowar = 0 if lowar<0

generate graphvar = 1  if pct_goldenshare == 1
replace  graphvar = 3 if pct_goldenshare == 2
replace  graphvar = 5 if pct_goldenshare == 3
replace  graphvar = 7 if pct_goldenshare == 4

twoway (bar meanvar graphvar  , lcolor(black) graphregion(fcolor(white) ) bargap(100)  fintensity(0) plotregion(color(white) ) xlabel(, valuelabel angle(horizontal) nogrid) ///
	xlabel(1 "0%" 3 "1-23%" 5 "23-30%" 7 ">30%", valuelabel angle(horizontal) nogrid)  ytitle("% Direct party effect")  title("Time periods", size(medium)) /// 
	 ylabel(0(0.2)0.8, nogrid) xsize(4) ysize(4) xtitle(% of Golden age/TS,size(medsmall))legend(off) name(gr1a, replace) ///
	  )   ///
	 (scatter meanvar graphvar, ms(i) mlab(n) mlabpos(2) mlabcolor(black)) ///
	 (rcap hivar lowar graphvar, lcolor(black) yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid)) //
	 
cd  "$GRAPHDIR"
graph export Fig_1.png, replace width(3600)
graph export Fig_1.tif, replace width(3600)
cd  "$DATADIR"	 

*Figure 2: Measure of inequality and partisan effects on inequality
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

bysort ineq_meas: su partyeffect

ttest partyeffect if ineq_meas <3, by(ineq_meas) //n.s.
ttest partyeffect if ineq_meas !=2, by(ineq_meas) //n.s.
ttest partyeffect if ineq_meas !=1, by(ineq_meas) //n.s.

collapse (mean) meanvar= partyeffect (sd) sdwrite=partyeffect (count) n=partyeffect  , by(ineq_meas)

*upper and lower values of the confidence interval.
    generate hivar = meanvar + invttail(n-1,0.05)*(sdwrite / sqrt(n))
    generate lowar = meanvar - invttail(n-1,0.05)*(sdwrite / sqrt(n))
	replace lowar = 0 if lowar<0

generate graphvar = ineq_meas    if ineq_meas == 1
replace  graphvar = ineq_meas+1  if ineq_meas == 2
replace  graphvar = ineq_meas+2 if ineq_meas == 3


twoway (bar meanvar graphvar, lcolor(black) graphregion(fcolor(white) ) bargap(200)  fintensity(0) plotregion(color(white) ) ///
	yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid)  ///
	xlabel(1 "Gini" 3 "Ratio" 5 "Share", valuelabel angle(45) nogrid) ytitle("% Direct party effect") ///
	title("a)", size(medsmall)) xtitle(Measurement of inequality, size(medsmall))legend(off) name(gr2a, replace) ) ///
	 (scatter meanvar graphvar, ms(i) mlab(n) mlabpos(2) mlabcolor(black) )  ///
	 (rcap hivar lowar graphvar, lcolor(black) yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid))	
	
*Fig 2b: Gini:
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

bysort gini_gr: su partyeffect
ttest partyeffect if gini_gr<3, by(gini_gr) //Pre vs. post: 0.005
ttest partyeffect if gini_gr!=2, by(gini_gr) //Pre vs. prevspost: 0.0001

clonevar gini_d=gini_gr
recode gini_d(3=2)
ttest partyeffect if gini_gr!=2, by(gini_d) //Pre vs. post/prepost: 0.0001

collapse (mean) meanvar= partyeffect (sd) sdwrite=partyeffect (count) n=partyeffect, by(gini_gr)

* and lower values of the confidence interval.
    generate hivar = meanvar + invttail(n-1,0.05)*(sdwrite / sqrt(n))
    generate lowar = meanvar - invttail(n-1,0.05)*(sdwrite / sqrt(n))
	replace lowar = 0 if lowar<0

generate graphvar = 1  if gini_gr == 1
replace  graphvar = 5 if gini_gr == 2
replace  graphvar = 3 if gini_gr == 3

twoway (bar meanvar graphvar, lcolor(black) graphregion(fcolor(white) ) bargap(100)  fintensity(0) plotregion(color(white) ) xlabel(, valuelabel angle(horizontal) nogrid) ///
	xlabel(1 " Pre " 3 " Diff. " 5 " Post", valuelabel angle(45) nogrid)  ytitle("% Direct party effect") /// 
	title("b)", size(medsmall))  ylabel(0(0.2)0.8, nogrid)  xtitle(Gini,size(medsmall))legend(off))  ///
	 (scatter meanvar graphvar, ms(i) mlab(n) mlabpos(2) mlabcolor(black) name(gr2b, replace))  ///
	 (rcap hivar lowar graphvar, lcolor(black) yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid))	 
	 

*Fig2c: Top-income vs. rest
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear
bysort toprest: su partyeffect
ttest partyeffect, by(toprest) level(90)  // sign.

collapse (mean) meanvar= partyeffect (sd) sdwrite=partyeffect (count) n=partyeffect, by(toprest)

* upper and lower values of the confidence interval.
    generate hivar = meanvar + invttail(n-1,0.05)*(sdwrite / sqrt(n))
    generate lowar = meanvar - invttail(n-1,0.05)*(sdwrite / sqrt(n))
	replace lowar = 0 if lowar<0

generate graphvar = 2  if toprest == 1
replace  graphvar = 4 if toprest == 0

twoway (bar meanvar graphvar, lcolor(black) graphregion(fcolor(white) ) bargap(0)  fintensity(0) plotregion(color(white) ) xlabel(, valuelabel angle(horizontal) nogrid) ///
	 xlabel(2 " Top" 4 " Rest", valuelabel angle(45) nogrid)  ytitle("% Direct party effect")   /// 
	 ylabel(0(0.2)0.8, nogrid) title("c)", size(medsmall)) xtitle(Top income vs. Rest,size(medsmall))legend(off)) ///
	(scatter meanvar graphvar, ms(i) mlab(n) mlabpos(2) mlabcolor(black) name(gr2c, replace))  ///
	 (rcap hivar lowar graphvar, lcolor(black) yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid))
	 

graph combine gr2a gr2b gr2c, col(3) ycommon xcommon title("Measure of inequality", size(medium)) ///
	ysize(3) xsize(4) 
cd  "$GRAPHDIR"
graph export Fig_2.png, replace width(3600)
graph export Fig_2.tif, replace width(3600)
cd  "$DATADIR"

*Figure 3: Conceptualization of partisan effects on inequality

*Fig 3a: Cumulative measure
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

bysort ideol_cum: su partyeffect
ttest partyeffect, by(ideol_cum)
collapse (mean) meanvar= partyeffect (sd) sdwrite=partyeffect (count) n=partyeffect  , by(ideol_cum)

* upper and lower values of the confidence interval.
    generate hivar = meanvar + invttail(n-1,0.05)*(sdwrite / sqrt(n))
    generate lowar = meanvar - invttail(n-1,0.05)*(sdwrite / sqrt(n))
	replace lowar = 0 if lowar<0
	
generate graphvar = 2    if ideol_cum == 0
replace  graphvar = 4  if ideol_cum == 1

twoway (bar meanvar graphvar, lcolor(black) graphregion(fcolor(white) ) bargap(200)  fintensity(0) plotregion(color(white) ) ///
	yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid) xsize(4) ysize(6) ///
	xlabel(2 "No" 4 "Yes", valuelabel angle(horizontal) nogrid) ytitle("% Direct party effect") ///
	title("a)", size(medium)) xtitle("Cumulative partisan effects", size(medsmall))legend(off) name(gr3a, replace) ) ///
	 (scatter meanvar graphvar, ms(i) mlab(n) mlabpos(2) mlabcolor(black) ) ///
	 (rcap hivar lowar graphvar, alcolor(black) yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid))

*Fig.3b) IV vs. DV
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

bysort party_control: su partyeffect
ttest partyeffect, by(party_control)
collapse (mean) meanvar= partyeffect (sd) sdwrite=partyeffect (count) n=partyeffect  , by(party_control)

* upper and lower values of the confidence interval.
    generate hivar = meanvar + invttail(n-1,0.05)*(sdwrite / sqrt(n))
    generate lowar = meanvar - invttail(n-1,0.05)*(sdwrite / sqrt(n))
	replace lowar = 0 if lowar<0
	
generate graphvar = 2   if party_control == 1
replace  graphvar = 4  if party_control == 0


twoway (bar meanvar graphvar, lcolor(black) graphregion(fcolor(white) ) bargap(200)  fintensity(0) plotregion(color(white) ) ///
	yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid) xsize(4) ysize(6) ///
	xlabel(4 "IV" 2 "Control", valuelabel angle(horizontal) nogrid)  ytitle("% Direct party effect") ///
	title("b)", size(medium)) xtitle("Partisan effects as...", size(medsmall))legend(off) name(gr3b, replace) ) ///
	 (scatter meanvar graphvar, ms(i) mlab(n) mlabpos(2) mlabcolor(black) )  ///
	 (rcap hivar lowar graphvar, lcolor(black) yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid))
	 	 

graph combine gr3a gr3b, ycommon xcommon row(1) ysize(4) xsize(6) ///
	title("Conceptualization and status of partisan effects", size(medium)) //
cd  "$GRAPHDIR"
graph export Fig_3_old.png, replace width(3600)
cd  "$DATADIR"

*Fig.3c) All controls
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

bysort controls_total: su partyeffect
su controls_total
su controls_total,d

xtile controls_total_3=controls_total, nq(2)
bysort controls_total_3: su controls_total

ttest partyeffect, by(controls_total_3) //44% vs. 30%

collapse (mean) meanvar= partyeffect (sd) sdwrite=partyeffect (count) n=partyeffect  , by(controls_total_3)

* upper and lower values of the confidence interval.
    generate hivar = meanvar + invttail(n-1,0.05)*(sdwrite / sqrt(n))
    generate lowar = meanvar - invttail(n-1,0.05)*(sdwrite / sqrt(n))
	replace lowar = 0 if lowar<0
	
generate graphvar = 2   if controls_total_3 == 1
replace  graphvar = 4  if controls_total_3 == 2

twoway (bar meanvar graphvar, lcolor(black) graphregion(fcolor(white) ) bargap(200)  fintensity(0) plotregion(color(white) ) ///
	yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid)  ///
	xlabel(2 "0-5" 4 "6-8", valuelabel angle(horizontal) nogrid)  ytitle("% Direct party effect") ///
	title("c)", size(medium)) xtitle("Number of policy channels", size(medsmall)) legend(off) name(gr3c, replace) ) ///
	 (scatter meanvar graphvar, ms(i) mlab(n) mlabpos(2) mlabcolor(black) )  ///
	 (rcap hivar lowar graphvar, lcolor(black) yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid))
	 	 
*Combined graph:
graph combine gr3a gr3b gr3c, ycommon xcommon row(1) ysize(3) xsize(4) ///
	title("Conceptualization and status of partisan effects", size(medium)) //
cd  "$GRAPHDIR"
graph export Fig_3.png, replace width(3600)
graph export Fig_3.tif, replace width(3600)

cd  "$DATADIR"	 

*3) Regression analysis
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

*3a) Table 1

melogit partyeffect c.goldenshare ib0.party_control i.ineq_meas   ib0.ideol_cum  controls_total  c.jipf c.n_obs   , vce(robust) ||paper_id:
 est store m1a
 
 est restore m1a
 margins, over(ineq_meas) pwcompare level (90)
 margins, over(ineq_meas) level (90)

 margins, over(ideol_cum)  level (90) //31 vs. 50%
  margins, over(ideol_cum) pwcompare  level (90) //19%

 margins, over(party_control) pwcompare level (90) //17%
 margins, dydx(goldenshare) pwcompare level (90) //23%


melogit partyeffect c.goldenshare toprest  ib0.ideol_cum ib0.party_control controls_total c.jipf c.n_obs   , vce(robust) ||paper_id:
 est store m2a
 est restore m2a
 margins, over(toprest) pwcompare
 margins, dydx(toprest) 
 
  margins, over(ideol_cum)  level (90) //30 vs. 52%
  margins, over(ideol_cum) pwcompare  level (90) //22%
 
  margins, over(party_control)  level (90) //34-52%
  margins, over(party_control) pwcompare level (90) //17% 
  
    margins, at((p25) controls_total) at((p75) controls_total) //39-45
    margins, at((p25) controls_total) at((p75) controls_total) pwcompare //-7
    margins, at((min) controls_total) at((max) controls_total) //32-59 (27%)
    margins, at((min) controls_total) at((max) controls_total) pwcompare //33-59 (27%)

 
melogit partyeffect c.goldenshare i.gini_gr  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs   , vce(robust) ||paper_id:
 est store m3a 
  est restore m3a
 margins, over(gini_gr) level(90)

 cd  "$RESULTSDIR" 
esttab m1a m3a m2a using Table_1.rtf, label replace  compress nogaps star(* 0.10 ** 0.05 *** 0.01)  ///
se(2) b(2) aic(2) bic(2) mtitle( "Model 1" "Model 2" "Model 3") nobase eqlabels(none) ///
coeflabels( 1.party_control "Partisan eff.=control" 1.ideol_cum "Cumul. partisan eff."  ///
 2.ineq_meas "Income ratios" 3.ineq_meas "Top income shares" ///
1.toprest_paper "Top income (ratio & share)" jipf "JIF"   goldenshare "% of Golden age"  ///
  controls_total "Number of policy channels" ///
 n_obs "N of observations"  _cons "Constant") ///
 order( *goldenshare *ineq_meas *gini_gr *toprest  *ideol_cum *party_control *controls_total)
cd  "$DATADIR"  

*Figure 4: Predicted probabilities plot

gen graph_id=_n/2 in 1/38
gen graph_x=graph_id-1

gen effect=.
gen upper=.
gen lower=.

*Golden share
est restore m1a
margins,at((min)goldenshare)   post level (90) //45%
matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V


forval i=1/1 {
	local j=`i'-1
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
}

est restore m1a
margins,at( (max)goldenshare) post level (90) //38
matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V


forval i=1/1 {
	local j=`i'-1
	replace effect=b[1,`i'] 				     if graph_x==`j'+1
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'+1
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'+1
}  
  
  
est restore m1a
  
margins, over(ineq_meas) post level (90)
matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V


forval i=1/3 {
	local j=`i'-1
	replace effect=b[1,`i'] 				     if graph_x==`j'+2.5
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'+2.5
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'+2.5
}

 *Gini
est restore m3a
 margins, over(gini_gr) level(90) 
 matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V
forval i=1/3 {
	local j=`i'-1
	replace effect=b[1,`i'] 				     if graph_x==`j'+6
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'+6
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'+6
}
 
*Top vs. rest
 est restore m2a 
 margins, at(toprest=0) level(90) 
 matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V
forval i=1/1 {
	local j=`i'-1
	replace effect=b[1,`i'] 				     if graph_x==`j'+9.5
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'+9.5
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'+9.5
}

 est restore m2a 
 margins, at(toprest=1) level(90) 
 matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V
forval i=1/1 {
	local j=`i'-1
	replace effect=b[1,`i'] 				     if graph_x==`j'+10.5
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'+10.5
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'+10.5
}

*Cumulative ms
   est restore m2a
margins, at(ideol_cum=0) level (90) //32%
matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'-1
	replace effect=b[1,`i'] 				     if graph_x==`j'+12
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'+12
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'+12
}

est restore m2a
margins, at(ideol_cum=1) level (90) //57%
matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'-1
	replace effect=b[1,`i'] 				     if graph_x==`j'+13
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'+13
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'+13
}

*Control variable 
   est restore m2a
 margins, at(party_control=1) pwcompare level (90) //31%
matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'-1
	replace effect=b[1,`i'] 				     if graph_x==`j'+14.5
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'+14.5
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'+14.5
}

   est restore m2a
 margins, at(party_control=0) pwcompare level (90) //55%
matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'-1
	replace effect=b[1,`i'] 				     if graph_x==`j'+15.5
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'+15.5
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'+15.5
}
su controls_total, d
 est restore m2a
 margins, at((min)controls_total)  level (90) //60% für 0 (46% p25=4)
matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'-1
	replace effect=b[1,`i'] 				     if graph_x==`j'+17
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'+17
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'+17
}

 est restore m2a
 margins, at((max)controls_total) level (90) //3% =6 (32 für max)
matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'-1
	replace effect=b[1,`i'] 				     if graph_x==`j'+18
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'+18
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'+18
}

su partyeffect

* twoway plot with addplot option
twoway ||  scatter effect graph_x, yaxis(1) yscale(range(0 0.8)  axis(1))   ///
		title("Conceptualization and status of partisan effects",size(medsmall)) ///
		ytitle("Predicted probabilities", size(medsmall) axis(1))  ///
	    ylabel(0(0.2)0.8, angle(0) nogrid) msymbol(o) ///
		xscale(range(-0.25 18.25)) ///
		yline(0.37, lpattern(dash) lwidth(thin)) ///
		xlabel(0 "Min" 1 "Max"  2.5 "Gini" 3.5 "Ratio" 4.5 "Share" 6 "Pre" 7 "Pos" 8 "Pr/Po" 9.5 "No" 10.5 "Yes" 12 "No" 13 "Yes" 14.5 "Ctrl" 15.5 "IV" 17 "Min" 18 "Max", nogrid labsize(medsmall))	 mcolor(black)  ///
		 text(0.02 0.5 "Golden age", size(medsmall))  /// 
		 text(0.02 7 "Type of Gini", size(medsmall))  /// 
		 text(0.02 17.5 "Channels", size(medsmall))  /// 
		 text(0.02 15 "Status", size(medsmall))  /// 
		 text(0.02 12.5 "Cumulative", size(medsmall))  /// 
		 text(0.02 10 "Top income", size(medsmall))  /// 
		 text(0.02 3.5 "Type of inequality", size(medsmall))  /// 
		 xline(1.75, lwidth(thin)) xline(5.25, lpattern(dot) lwidth(thin)) xline(8.75, lpattern(dot)lwidth(thin)) xline(11.25, lpattern(solid)lwidth(thin)) xline(16.25, lpattern(dot)lwidth(thin)) xline(13.75, lpattern(dot)lwidth(thin))  ///
	|| rcap upper lower graph_x, yaxis(1) ///
		lcolor(black) ysize(3) xsize(6) ///
		graphregion(color(white)) xtitle("") ///
		legend(off) title("",size(small)) ///
 text(0.79 0.5 "I. Time")  text(0.79 7 "II. Inequality") text(0.79 15 "III. Partisanship")
 		
drop graph_id graph_x effect upper lower 

cd  "$GRAPHDIR"
graph export "Fig_4.png", width(3600) replace	 	
graph export "Fig_4.tif", width(3600) replace	 		
cd  "$DATADIR"  
 
*Figure 5: Combined predicted probabilities for partisan effects on inequalty

*Full model with all variables and the number of relevant controls
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

melogit partyeffect  1.toprest  1.ideol_cum 1.party_control  c.jipf c.n_obs c.controls_total goldenshare  , vce(robust) ||paper_id:
est store mx

*Prepare variables for graph
gen graph_id=_n in 1/15
gen graph_x=graph_id-1

gen effect=.
gen upper=.
gen lower=.

*Variable for distribution of observations
gen frequency=.

gen factors=.

*0 All at the lower values
est restore mx
margins if party_control==1 &toprest==0 &ideol_cum==0 & controls_total>=6 , post level(90) //11%, n=29

matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'-1
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	count if party_control==1 &toprest==0 &ideol_cum==0  & controls_total>=6 
	replace frequency=r(N) if graph_x==`j'
	replace factors=0 if graph_x==`j'
}


**1 factor at party effect value
*5  party IV 
est restore mx
margins if party_control==0 &toprest==0 &ideol_cum==0 & controls_total>=6 , post level(90) //17%

matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	count if party_control==0 &toprest==0 &ideol_cum==0  & controls_total<=5 //7
	replace frequency=r(N) if graph_x==`j'
	replace factors=1 if graph_x==`j'
}

**Toprest
est restore mx
margins if party_control==1 &toprest==1 &ideol_cum==0 & controls_total>=6 , post level(90) //26%

matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'+1
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	count if party_control==1 &toprest==1 &ideol_cum==1  & controls_total>=6 //38
	replace frequency=r(N) if graph_x==`j'
	replace factors=1 if graph_x==`j'
}

*6 Cumulative
est restore mx
margins if party_control==1 &toprest==0 &ideol_cum==1 & controls_total>=6 , post level(90) //31%

matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'+2
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	count if party_control==1 &toprest==1 &ideol_cum==1  & controls_total>=6 //62
	replace frequency=r(N) if graph_x==`j'
	replace factors=1 if graph_x==`j'

}

***2 factors at party effect value - all good

*5  party IV & channels
est restore mx
margins if party_control==0 &toprest==0 &ideol_cum==0 & controls_total<=5 , post level(90) //27%

matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'+3
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	count if party_control==0 &toprest==0 &ideol_cum==0  & controls_total<=5 //22
	replace frequency=r(N) if graph_x==`j'
	replace factors=2 if graph_x==`j'

}

**Party IV & Toprest
est restore mx
margins if party_control==0 &toprest==1 &ideol_cum==0 & controls_total>=6 , post level(90) //38%

matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'+4
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	count if party_control==1 &toprest==1 &ideol_cum==1  & controls_total>=6 //9
	replace frequency=r(N) if graph_x==`j'
	replace factors=2 if graph_x==`j'
}


*7 Low channels & Toprest
est restore mx
margins if party_control==1 &toprest==1 &ideol_cum==0 & controls_total<=5 , post level(90) //44%

matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'+5
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	count if party_control==1 &toprest==1 &ideol_cum==0  & controls_total<=5  //7
	replace frequency=r(N) if graph_x==`j'
	replace factors=2 if graph_x==`j'
}

*6 Cumulative & channels
est restore mx
margins if party_control==1 &toprest==0 &ideol_cum==1 & controls_total<=5 , post level(90) //42%

matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'+6
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	count if party_control==1 &toprest==1 &ideol_cum==1  & controls_total>=6 //15
	replace frequency=r(N) if graph_x==`j'
	replace factors=2 if graph_x==`j'
}

*6 Cumulative measure & toprest
est restore mx
margins if party_control==1 &toprest==1 &ideol_cum==1 & controls_total>=6 , post level(90) //43%

matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'+7
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	count if party_control==1 &toprest==1 &ideol_cum==1  & controls_total>=6 //7
	replace frequency=r(N) if graph_x==`j'
		replace factors=2 if graph_x==`j'
}

*Party IV & cumulative
est restore mx
margins if party_control==0 &toprest==0 &ideol_cum==1 & controls_total>=6 , post level(90) //45%

matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'+8
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	count if party_control==1 &toprest==1 &ideol_cum==1  & controls_total>=6 //13
	replace frequency=r(N) if graph_x==`j'
		replace factors=2 if graph_x==`j'
}

*1 Low, 3 high
*5 Only party Control 
est restore mx
margins if party_control==1 &toprest==1 &ideol_cum==1 & controls_total<=5 , post level(90) //66%

matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'+9
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	count if party_control==0 &toprest==0 &ideol_cum==0  & controls_total<=5 //33
	replace frequency=r(N) if graph_x==`j'
	replace factors=3 if graph_x==`j'
}

**Only toprest=0
est restore mx
margins if party_control==0 &toprest==0 &ideol_cum==1 & controls_total<=5 , post level(90) //57%

matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'+10
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	count if party_control==1 &toprest==1 &ideol_cum==1  & controls_total>=6 //34
	replace frequency=r(N) if graph_x==`j'	
	replace factors=3 if graph_x==`j'
}

*6 Only short term
est restore mx
margins if party_control==0 &toprest==1 &ideol_cum==0 & controls_total<=5 , post level(90) //55%

matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'+11
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	count if party_control==1 &toprest==1 &ideol_cum==1  & controls_total<=5 //42
	replace frequency=r(N) if graph_x==`j'
	replace factors=3 if graph_x==`j'
}

*6 Only channels=0
est restore mx
margins if party_control==0 &toprest==1 &ideol_cum==1 & controls_total>=6 , post level(90) //72%

matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'+12
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	count if party_control==1 &toprest==1 &ideol_cum==1  & controls_total>=6 //19
	replace frequency=r(N) if graph_x==`j'
	replace factors=3 if graph_x==`j'
}

*13 All high
est restore mx
margins if party_control==0 &toprest==1 &ideol_cum==1 & controls_total<=5 , post level(90) //78%

matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'+13
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	count if party_control==0 &toprest==1 &ideol_cum==1  & controls_total<=5  //12
	replace frequency=r(N) if graph_x==`j'
	replace factors=4 if graph_x==`j'
}

***Combine predicted probabilities
foreach var of varlist effect upper lower {
gen `var'_mean=.
}

foreach var of varlist effect upper lower {
forvalues i=0(1)4 {
	su `var' if factors==`i'
	replace `var'_mean=r(mean)  if factors==`i'
	}
}

bysort factors: egen freq_tot=total(frequency)
bysort factors: egen freq_mean=mean(frequency)
su freq_tot freq_mean

twoway || bar freq_mean factors	,yaxis(2) ylab(0(10)30, axis(2)) yscale(range(0 10) axis(2)) fcolor(gs15) bcolor(gs15) barwidth(0.4)  ytitle("Average Number of observations", size(medsmall) axis(2)) ///
||  scatter effect_mean factors if factors<=4, yaxis(1) yscale(range(0 1)  axis(1))   ///
		title("Combined effects",size(medsmall)) ///
		ytitle("Predicted probabilities", size(medsmall) axis(1))  ///
	    ylabel(0(0.2)1, angle(0) nogrid) ///
		xscale(range(-0.5 4.5)) ///
		xlabel(0 1 2 3 4, nogrid  labsize(medsmall)) ///
		mcolor(black) msymbol(o) ///
	|| rcap upper_mean lower_mean factors if factors<=4, yaxis(1) ///
		lcolor(black) ysize(3) xsize(4) ///
		graphregion(color(white)) xtitle("") ///
		legend(off) title("")	 xtitle("") ///
		|| function y = 0.425,           ///
		range(-0.5 4.5) clpattern(dash) clcolor(black) clwidth(thin)  /// 
		 name(gr1, replace) yscale(alt) yscale(alt axis(2))	///
			  xtitle(Number of predictors at values associated with partisan effects,size(medsmall)) //	
 
cd  "$GRAPHDIR"
graph export "Fig_5.png", width(3600) replace	 	
graph export "Fig_5.tif", width(3600) replace	 			
cd  "$DATADIR" 

drop frequency graph_id graph_x upper lower effect
 
*****************************************************
************ SUPPLEMENTARY FILES ********************
*****************************************************


*****************************************************	
******** S-A: Descriptive information ******** 
*****************************************************

use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

* Table S-A1: Descriptive information
estpost tabstat partyeffect goldenshare ineq_meas gini_gr toprest jipf n_obs policies_control corp_control  postind_control glob_control controls_total, c(stat) stat(mean median sd min max n)

cd  "$RESULTSDIR"
esttab using Table_SA1.rtf, replace ///
 cells("count ( fmt(%9.0f)) mean ( fmt(%9.2f)) sd ( fmt(%9.2f)) min ( fmt(%9.2f)) max( fmt(%9.2f)) ") noobs nonumber ///
   collabels("Obs." "Mean" "Std. Dev" "Min" "Max") ///
  nomtitle nonote label //
cd  "$DATADIR"

*Figure S-A1: Different policy channels and partisan effects on inequality

*Fig A1a: Corporatism

tab corp_control
xtile corp_control_2=corp_control, nq(2)
bysort corp_control_2: su partyeffect
bysort corp_control_2: tab corp_control
ttest partyeffect, by(corp_control_2) // 0-1 control: 55%, 2-4 Controls: 20%
collapse (mean) meanvar= partyeffect (sd) sdwrite=partyeffect (count) n=partyeffect  , by(corp_control_2)

* upper and lower values of the confidence interval.
    generate hivar = meanvar + invttail(n-1,0.05)*(sdwrite / sqrt(n))
    generate lowar = meanvar - invttail(n-1,0.05)*(sdwrite / sqrt(n))
	replace lowar = 0 if lowar<0
	
generate graphvar = 3   if corp_control_2 == 1
replace  graphvar = 5  if corp_control_2 == 2


twoway (bar meanvar graphvar, lcolor(black) graphregion(fcolor(white) ) bargap(200)  fintensity(0) plotregion(color(white) ) ///
	yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid)  ///
	xlabel(3 "0-1 variables" 5 ">1 variables", valuelabel angle(horizontal) nogrid) ytitle("% Direct party effect") ///
	title("a)", size(medium)) xtitle("Corporatism", size(medsmall))legend(off) name(gr4a, replace) ) ///
	 (scatter meanvar graphvar, ms(i) mlab(n) mlabpos(2) mlabcolor(black) ) ///
	 (rcap hivar lowar graphvar, alcolor(black) yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid))

*Fig.A1b) policies_control
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

bysort policies_control: su partyeffect
xtile policies_control_2=policies_control, nq(2)
bysort policies_control_2: su policies_control 
ttest partyeffect, by(policies_control_2) //30% vs. 55%
collapse (mean) meanvar= partyeffect (sd) sdwrite=partyeffect (count) n=partyeffect  , by(policies_control_2)

* upper and lower values of the confidence interval.
    generate hivar = meanvar + invttail(n-1,0.05)*(sdwrite / sqrt(n))
    generate lowar = meanvar - invttail(n-1,0.05)*(sdwrite / sqrt(n))
	replace lowar = 0 if lowar<0
	
generate graphvar = 5   if policies_control_2 == 2
replace  graphvar = 3  if policies_control_2 == 1

twoway (bar meanvar graphvar, lcolor(black) graphregion(fcolor(white) ) bargap(200)  fintensity(0) plotregion(color(white) ) ///
	yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid)  ///
	xlabel(3 "0-1 variables" 5 ">1 variables", valuelabel angle(horizontal) nogrid)  ytitle("% Direct party effect") ///
	title("b)", size(medium)) xtitle("Policies", size(medsmall))legend(off) name(gr4b, replace) ) ///
	 (scatter meanvar graphvar, ms(i) mlab(n) mlabpos(2) mlabcolor(black) )  ///
	 (rcap hivar lowar graphvar, lcolor(black) yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid))
	 	 
*Fig.A1c) Globalization
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

xtile glob_control_2=glob_control, nq(2)

bysort glob_control_2: su partyeffect
bysort glob_control_2: su glob_control
replace glob_control_2=2 if glob_control==1
ttest partyeffect, by(glob_control_2) //0.39 vs. 0.4%
collapse (mean) meanvar= partyeffect (sd) sdwrite=partyeffect (count) n=partyeffect  , by(glob_control_2)

* upper and lower values of the confidence interval.
    generate hivar = meanvar + invttail(n-1,0.05)*(sdwrite / sqrt(n))
    generate lowar = meanvar - invttail(n-1,0.05)*(sdwrite / sqrt(n))
	replace lowar = 0 if lowar<0
	
generate graphvar = 3   if glob_control_2 == 1
replace  graphvar = 5  if glob_control_2 == 2

twoway (bar meanvar graphvar, lcolor(black) graphregion(fcolor(white) ) bargap(200)  fintensity(0) plotregion(color(white) ) ///
	yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid)  ///
	xlabel(3 "0-1 variables" 5 ">1 variables", valuelabel angle(horizontal) nogrid) ytitle("% Direct party effect") ///
	title("c)", size(medium)) xtitle("Globalization", size(medsmall))legend(off) name(gr4c, replace) ) ///
	 (scatter meanvar graphvar, ms(i) mlab(n) mlabpos(2) mlabcolor(black) ) ///
	 (rcap hivar lowar graphvar, alcolor(black) yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid))
	  
*Fig.A1d) Postindustrialization
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

xtile postind_control_2=postind_control, nq(2)


bysort postind_control_2: su partyeffect
bysort postind_control_2: su glob_control
ttest partyeffect, by(postind_control_2) //0.35 vs. 0.46%
collapse (mean) meanvar= partyeffect (sd) sdwrite=partyeffect (count) n=partyeffect  , by(postind_control_2)

* upper and lower values of the confidence interval.
    generate hivar = meanvar + invttail(n-1,0.05)*(sdwrite / sqrt(n))
    generate lowar = meanvar - invttail(n-1,0.05)*(sdwrite / sqrt(n))
	replace lowar = 0 if lowar<0
	
generate graphvar = 3   if postind_control_2 == 1
replace  graphvar = 5  if postind_control_2 == 2


twoway (bar meanvar graphvar, lcolor(black) graphregion(fcolor(white) ) bargap(200)  fintensity(0) plotregion(color(white) ) ///
	yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid)  ///
	xlabel(3 "0-1 variables" 5 ">1 variables", valuelabel angle(horizontal) nogrid) ytitle("% Direct party effect") ///
	title("d)", size(medium)) xtitle("Postindustrialization", size(medsmall))legend(off) name(gr4d, replace) ) ///
	 (scatter meanvar graphvar, ms(i) mlab(n) mlabpos(2) mlabcolor(black) ) ///
	 (rcap hivar lowar graphvar, alcolor(black) yscale(range(0(0.2)0.8)) ylabel(0(0.2)0.8, nogrid))
	 
graph combine gr4a gr4b gr4c gr4d, ycommon xcommon row(2) ysize(4) xsize(5) ///
	title("Policy channels", size(medium)) //
cd  "$GRAPHDIR"
graph export Fig_SA1.png, replace width(3600)
cd  "$DATADIR" 


*****************************************************	
*********** S-B: Examining publication bias *********
*****************************************************

use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

*Table S-B1: Explaining partisan effects on inequality: Journal impact and policy channelsest clear

melogit partyeffect 1.party_control##c.jipf c.controls_total c.n_obs , vce(robust)  ||paper_id: 
est store m4
melogit partyeffect 1.party_control##c.jipf##c.controls_total c.n_obs  , vce(robust)  ||paper_id: 
est store m5

*Output:  
 cd  "$RESULTSDIR"
esttab  m4 m5 using Table_B1.rtf, label replace compress wide onecell nogaps star(* 0.10 ** 0.05 *** 0.01) ///
se(2) b(2) aic(2) bic(2) mtitle("Model 1" "Model 2") nobase eqlabels(none) ///
coeflabels( 1.party_control "Partisan eff.=control" 1.ideol_cum "Cumul. partisan eff." ///
 2.ineq_meas "Income ratios" 3.ineq_meas "Top income shares" ///
1.toprest_paper "Top income (ratio & share)" jipf "JIF"   goldenshare "% of Golden age" ///
controls_total "Number of policy channels" ///
 n_obs "N of observations"  _cons "Constant") ///
 order( *party_control *jipf *controls_total)
cd  "$DATADIR"  
 
*Figure S-B1: Predicted probability of partisan effect conditional on variable status and impact 
 
*Two-way interaction
est restore m4
margins, over(party_control) at((p25) jipf) at((p75) jipf)  level(90) post
matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

gen graph_id=_n in 1/4
gen graph_x=graph_id-1

gen effect=.
gen upper=.
gen lower=.

forval i=1/4 {
	local j=`i'-1
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.96*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.96*sqrt(V[`i',`i']) if graph_x==`j'
}

twoway ||  scatter effect graph_x, yaxis(1) yscale(range(0 0.8)  axis(1))   ///
		title("",size(medsmall)) ///		xtitle("Journal impact factor",size(medsmall)) ///
		ytitle("Predicted probabilities", size(medsmall) axis(1)) msymbol(o)  ///
	    ylabel(0(0.1)0.8, angle(0) nogrid) ///
		xscale(range(-0.5 3.5)) ///
		xlabel(0  "IV/JIF(p25)" 1 "Ctrl/JIF(p25)" 2 "IV/JIF(p75)" 3 "Ctrl/JIF(p75)", nogrid) ///
		mcolor(black) ///
	|| rcap upper lower graph_x, yaxis(1) ///
		lcolor(black) ysize(4) xsize(5) ///
		graphregion(color(white)) ///
		legend(off) xtitle("") ///
		yline(0.375, lpattern(dash)) name(gr1, replace) //

 cd  "$GRAPHDIR"
graph export "Fig_SB1.png", width(3600) replace	 		
cd  "$DATADIR"
	
drop graph_id graph_x effect upper lower

*Figure S-B2: Marginal effect of party status conditional on Journal impact and channels 
		
*Three-way interaction
est restore m5
margins, dydx(jipf) at((p25)controls_total party_control=1) at( (p75)controls_total party_control=1)    post level(90)

matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

gen graph_id=_n in 1/3
gen graph_x=graph_id-1

gen effect=.
gen upper=.
gen lower=.

forval i=1/2 {
	local j=`i'-1
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.96*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.96*sqrt(V[`i',`i']) if graph_x==`j'
}

twoway ||  scatter effect graph_x, yaxis(1) yscale(range(-0.5 0.5)  axis(1))   ///
		title("",size(medsmall)) ///
		ytitle("Marginal effect on partisan effects", size(medsmall) axis(1))  ///
	    ylabel(-0.6(0.2)0.6, angle(0) nogrid) msymbol(o) ///
		xscale(range(-0.5 1.5)) xtitle("") ///
		xlabel(0  `" "Channels" "(p25)" "' 1  `" "Channels" "(p75)" "',nogrid) ///
		mcolor(black) ///
	|| rcap upper lower graph_x, yaxis(1) ///
		lcolor(black) ysize(4) xsize(5) ///
		graphregion(color(white)) ///
		legend(off) ///
		yline(0, lpattern(dash)) name(gr2, replace) ///

drop graph_id graph_x effect upper lower
			
cd  "$GRAPHDIR"
graph export "Fig_SB2.png", width(3600) replace	 		
cd  "$DATADIR"	

*Figure S-B3: Test statistics, status of partisan effects and journal impact (median split)

*Median split of journals based on their impact factor:
xtile jipf_2 = jipf, nq(2)
 
*Binning
tab tvalue
gen help=1
bysort tvalue jipf_2: egen total_t=total(help)
su total_t //1-18

bysort tvalue jipf_2 party_control: egen total_t2=total(help)
su total_t2 //1-18
 
 
*Colored 
clonevar x = tvalue
replace x =  x - 0.05

 clonevar x1 = tvalue
replace x1 =  x + 0.05

 clonevar x2 = tvalue
replace x2 =  x - 0.02


twoway (bar total_t2 x  if jipf_2==1 &(tvalue>-5 & tvalue<5) & party_control==0, xline(-1.96 1.96) xline(-1.645 1.645, lpattern(dash)) ylab(, nogrid) barwidth(0.3) xtitle(Test statistic) fcolor(green%10) fintensity(inten70)) ///
 (bar total_t2 x1  if jipf_2==1 &(tvalue>-5 & tvalue<5) & party_control==1, title(Low impact) barwidth(0.3) fcolor(navy%10) fintensity(inten70) name(gr1, replace) ytitle(N) ///
 legend(position(6) col(2) ///
           order(  1 "IV" ///
                    2 "Control")) )					
					
twoway (bar total_t2 x if jipf_2==2 &(tvalue>-5 & tvalue<5) & party_control==0, title(High impact) barwidth(0.3) fcolor(green%10) fintensity(inten70) ylab(, nogrid) xline(-1.96 1.96) xline(-1.645 1.645, lpattern(dash)) xlabel(, nogrid)) ///
 (bar total_t2 x2  if jipf_2==2 &(tvalue>-5 & tvalue<5)& party_control==1, barwidth(0.3) fcolor(navy%10) fintensity(70) xtitle(Test statistic) ytitle(N) ///
 legend(position(6) col(2) ///
           order(  1 "IV" ///
                    2 "Control")) name(gr2, replace))
					
graph combine gr1 gr2, col(1) xsize(3) ysize(4)	xcommon ycommon
cd  "$GRAPHDIR"
graph export Fig_SB3.png, replace width(3600)
cd  "$DATADIR"		


*****************************************************	
**S-C: Additional analyses and robustness checks
*****************************************************

*Table S-C1: Explaining partisan effects on inequality (separate models for each IV)
est clear
melogit partyeffect c.goldenshare jipf n_obs  , vce(robust)  ||paper_id:
est store m_cla1

melogit partyeffect 1.toprest jipf  n_obs   , vce(robust)  ||paper_id: 
est store m_cla2

local i=3
foreach var of varlist  ineq_meas gini_gr ideol_cum party_control  {
	melogit partyeffect i.`var' jipf n_obs , vce(robust)   ||paper_id:
	est store m_cla`i'
	local i = `i' + 1
}

melogit partyeffect c.controls_total jipf  n_obs   , vce(robust)  ||paper_id: 
est store m_cla7


*Output:  
 cd  "$RESULTSDIR"
esttab m_cla1 m_cla3 m_cla4 m_cla2 m_cla5 m_cla6 m_cla7  using Table_SC1.rtf, replace label  compress nogaps star(* 0.10 ** 0.05 *** 0.01)  ///
se(2) b(2) aic(2) bic(2) mtitle() nobase eqlabels(none) ///
coeflabels( 1.party_control "Partisan eff.=control" 1.ideol_cum "Cumul. partisan eff."  ///
 2.ineq_meas "Income ratios" 3.ineq_meas "Top income shares" ///
1.toprest_paper "Top income (ratio & share)" jipf "JIF"   goldenshare "% of Golden age" ///
 n_obs "N of observations" controls_total "Number of policy channels" ///
 n_obs "N of observations"  _cons "Constant") ///
 order( *goldenshare *ineq_meas *gini_gr *toprest *ideol_cum *party_control controls_total)
cd  "$DATADIR"


*Table S-C2: Explaining partisan effects on inequality (OLS vs. Logit Multi-level regression) 
est clear

melogit partyeffect c.goldenshare i.ineq_meas   1.ideol_cum 1.party_control controls_total  c.jipf c.n_obs  , vce(robust) ||paper_id:
 est store m1b
 
melogit partyeffect c.goldenshare i.gini_gr  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs , vce(robust) ||paper_id:
 est store m2b 
melogit partyeffect c.goldenshare toprest  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs , vce(robust) ||paper_id:
 est store m3b

*This one as OLS not, but the SEs are much smaller
mixed partyeffect c.goldenshare i.ineq_meas   1.ideol_cum 1.party_control controls_total c.jipf c.n_obs , vce(robust) ||paper_id:
 est store m1a

 mixed partyeffect c.goldenshare i.gini_gr  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs , vce(robust) ||paper_id:
 est store m2a 
 
mixed partyeffect c.goldenshare toprest  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs , vce(robust) ||paper_id:
 est store m3a
 
*Output:  
 cd  "$RESULTSDIR"
esttab m1a m1b m2a m2b m3a m3b  using Table_SC2.rtf, replace label compress nogaps star(* 0.10 ** 0.05 *** 0.01)  ///
se(2) b(2) aic(2) bic(2) mtitle( "M1 (OLS)" "M1 (Logit)" "M2 (OLS)" "M2 (Logit)" "M3 (OLS)" "M3 (Logit)") nobase eqlabels(none) ///
coeflabels( 1.party_control "Partisan eff.=control" 1.ideol_cum "Cumul. partisan eff."  ///
 2.ineq_meas "Income ratios" 3.ineq_meas "Top income shares" ///
1.toprest_paper "Top income (ratio & share)" jipf "JIF"   goldenshare "% of Golden age" controls_total "Number of policy channels" ///
 n_obs "N of observations"  _cons "Constant") ///
 order( *goldenshare *ineq_meas *gini_gr *toprest *ideol_cum *party_control controls_total)
cd  "$DATADIR"

*Table S-C3: Explaining partisan effects on inequality (only articles with at least 5 results) 
bysort paper_id: gen cluster_c=_N

est clear

melogit partyeffect c.goldenshare i.ineq_meas   1.ideol_cum 1.party_control  controls_total c.jipf c.n_obs   if cluster_c>=5, vce(robust) ||paper_id:
 est store m1a

melogit partyeffect c.goldenshare toprest  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs  if cluster_c>=5, vce(robust) ||paper_id:
 est store m3a
 
melogit partyeffect c.goldenshare i.gini_gr  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs  if cluster_c>=5 , vce(robust) ||paper_id:
 est store m2a 

melogit partyeffect c.goldenshare i.ineq_meas   1.ideol_cum 1.party_control controls_total  c.jipf c.n_obs   if cluster_c>=10, vce(robust) ||paper_id:
 est store m1b

melogit partyeffect c.goldenshare toprest  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs  if cluster_c>=10, vce(robust) ||paper_id:
 est store m3b
 
melogit partyeffect c.goldenshare i.gini_gr  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs  if cluster_c>=10 , vce(robust) ||paper_id:
 est store m2b  
 
*Output:  
cd  "$RESULTSDIR"
esttab m1a m1b m2a m2b m3a m3b using Table_SC3.rtf, replace  label  compress nogaps star(* 0.10 ** 0.05 *** 0.01)  ///
se(2) b(2) aic(2) bic(2) mtitle( "M1 (CL>=5)" "M1 (CL>=10)" "M2 (CL>=5)" "M2 (CL>=10)" "M3 (CL>=5)" "M3 (CL>=10)" "M4 (CL>=5)" "M4 (CL>=10)" "M5 (CL>=5)" "M5 (CL>=10)" "M6 (CL>=5)" "M6 (CL>=10)") nobase eqlabels(none) ///
coeflabels( 1.party_control "Partisan eff.=control" 1.ideol_cum "Cumul. partisan eff."  ///
 2.ineq_meas "Income ratios" 3.ineq_meas "Top income shares" controls_total "Number of policy channels" ///
1.toprest_paper "Top income (ratio & share)" jipf "JIF"   goldenshare "% of Golden age"  ///
 n_obs "N of observations"  _cons "Constant") ///
 order( *goldenshare *ineq_meas *gini_gr *toprest *ideol_cum *party_control controls_total)
cd  "$DATADIR"
 
 
*Table S-C4: Explaining partisan effects on inequality (excluding counterintuitive effects) 
est clear

melogit partyeffect c.goldenshare 1.party_control i.ineq_meas   1.ideol_cum  controls_total  c.jipf c.n_obs   , vce(robust) ||paper_id:
est store m_cl1
melogit partyeffect c.goldenshare toprest  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs   , vce(robust) ||paper_id:
est store m_cl5
melogit partyeffect c.goldenshare i.gini_gr  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs   , vce(robust) ||paper_id:
est store m_cl3

melogit partyeffect_exp c.goldenshare 1.party_control i.ineq_meas  controls_total 1.ideol_cum    c.jipf c.n_obs   , vce(robust) ||paper_id:
est store m_cl2
melogit partyeffect_exp c.goldenshare toprest  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs   , vce(robust) ||paper_id:
est store m_cl6
melogit partyeffect_exp c.goldenshare i.gini_gr  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs   , vce(robust) ||paper_id:
est store m_cl4

*Output:  
 cd  "$RESULTSDIR"
esttab m_cl1 m_cl2 m_cl3 m_cl4 m_cl5 m_cl6 using Table_SC4.rtf, replace label compress nogaps star(* 0.10 ** 0.05 *** 0.01)  ///
se(2) b(2) aic(2) bic(2) mtitle() nobase eqlabels(none) ///
coeflabels( 1.party_control "Partisan eff.=control" 1.ideol_cum "Cumul. partisan eff." ///
 2.ineq_meas "Income ratios" 3.ineq_meas "Top income shares" ///
1.toprest_paper "Top income (ratio & share)" jipf "JIF"   goldenshare "% of Golden age" ///
n_obs "N of observations" controls_total "Number of policy channels" ///
 n_obs "N of observations"  _cons "Constant") ///
 order( *goldenshare *ineq_meas *gini_gr *toprest *ideol_cum *party_control controls_total) 
cd  "$DATADIR"


*Table S-C5: Explaining partisan effects on inequality (Logistic regression) 
est clear
logit partyeffect c.goldenshare i.ineq_meas   1.ideol_cum 1.party_control  controls_total c.jipf c.n_obs  , cluster (paper_id)
 est store m1a

logit partyeffect c.goldenshare toprest  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs  , cluster(paper_id) 
 est store m3a
 
logit partyeffect c.goldenshare i.gini_gr  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs   ,cluster(paper_id)  
 est store m2a 

logit partyeffect c.goldenshare i.ineq_meas   1.ideol_cum 1.party_control controls_total  c.jipf c.n_obs  , vce (robust)
 est store m1b

logit partyeffect c.goldenshare toprest  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs  , vce (robust)
 est store m3b
 
logit partyeffect c.goldenshare i.gini_gr  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs   ,vce (robust)
 est store m2b

*Output:  
 cd  "$RESULTSDIR"
esttab m1a m1b m2a m2b m3a m3b using Table_SC5.rtf, replace label compress nogaps star(* 0.10 ** 0.05 *** 0.01)  ///
se(2) b(2) aic(2) bic(2) mtitle( "M1 (CL)" "M1 (RSE)" "M2 (CL)" "M2 (RSE)" "M3 (CL)" "M3 (RSE)") nobase eqlabels(none) ///
coeflabels( 1.party_control "Partisan eff.=control" 1.ideol_cum "Cumul. partisan eff."  ///
 2.ineq_meas "Income ratios" 3.ineq_meas "Top income shares" ///
1.toprest_paper "Top income (ratio & share)" jipf "JIF"   goldenshare "% of Golden age" controls_total "Number of policy channels" ///
 n_obs "N of observations"  _cons "Constant") ///
 order( *goldenshare *ineq_meas *gini_gr *toprest  *ideol_cum *party_control controls_total )
cd  "$DATADIR"

* Table S-C6: Explaining partisan effects on inequality: Effect of policy channels

use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

est clear

local i=1
foreach var of varlist   corp_control policies_control postind_control glob_control   controls_total {
	melogit partyeffect c.`var'  n_obs c.jipf , vce(robust)  ||paper_id: 
	est store m_cl`i'
	local i = `i' + 1
}

cd  "$RESULTSDIR"
esttab m_cl* using Table_SC6.rtf, replace label compress nogaps star(* 0.10 ** 0.05 *** 0.01)  ///
se(2) b(2) aic(2) bic(2) mtitle("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6") nobase eqlabels(none) ///
coeflabels( 1.party_control "Partisan eff.=control" 1.ideol_cum "Cumul. partisan eff." ///
 2.ineq_meas "Income ratios" 3.ineq_meas "Top income shares" ///
1.toprest_paper "Top income (ratio & share)" jipf "JIF"   goldenshare "% of Golden age" ///
 n_obs "N of observations" controls_total "Number of policy channels" ///
   policies_control "policies_control" corp_control "Corporatism"  ///
postind_control "Postindustrialization" glob_control "Globalization" controls_total "Total N of channels" ///
 n_obs "N of observations"  _cons "Constant") //
 order(*corp_control  *policies_control  *postind* *glob* controls_total *jipf *n_obs)
cd  "$DATADIR" 
 
* Figure SC1: Marginal effect of different policy channels on partisan effects
gen graph_id=_n in 1/5
gen graph_x=graph_id-1

gen effect=.
gen upper=.
gen lower=.
 
 
 *Corporatism
 est restore m_cl1
 margins, dydx(corp_control) pwcompare level(90) //-6%
 matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V
forval i=1/1 {
	local j=`i'-1
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
}
 
*policies_control
est restore m_cl2
margins,dydx(policies_control) pwcompare  post level (90) //0.00
matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
}
 
*Endo
   est restore m_cl3
margins, dydx(postind_control) level (90) //-0.00
matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'+1
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
}

*Exo
   est restore m_cl4
 margins, dydx(glob_control) pwcompare level (90) //-7%
matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'+2
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
}

*Policy channels - total N
   est restore m_cl5
 margins, dydx(controls_total)  level (90) //-3%
matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'+3
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
}

* twoway plot with addplot option
twoway ||  scatter effect graph_x, yaxis(1) yscale(range(0 0.3)  axis(1))   ///
		ytitle("Marginal effect on partisan effects", size(medsmall) axis(1))  ///
	    ylabel(-0.3(0.1)0.3, angle(0) nogrid) msymbol(o) ///
		xscale(range(-0.5 4.5)) ///
		xlabel( 0 "Corp" 1 "Pol" 2 "Post" 3 "Glob" 4 "Total", nogrid) ///
		mcolor(black)  ///
	|| rcap upper lower graph_x, yaxis(1) ///
		lcolor(black) ysize(3) xsize(4) ///
		graphregion(color(white)) xtitle("") ///
		legend(off) title("Policy channels",size(medsmall)) ///	 xtitle("") ///
		yline(0, lpattern(dash)) name(gr2, replace) //
 cd  "$GRAPHDIR"
graph export "Fig_SC1.png", width(3600) replace	 		
cd  "$DATADIR"
 		
drop graph_id graph_x effect upper lower  
 
*Table S-C7: Explaining partisan effects on inequality: Temporal effect of policy channels
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

gen short_n=policies_control
gen long_n=controls_total-policies_control

su short_n long_n

est clear

melogit partyeffect  i.ineq_meas ib0.ideol_cum##c.short_n 1.party_control  c.jipf c.n_obs goldenshare  , vce(robust) ||paper_id:	
est store m_cl1
	
melogit partyeffect  i.ineq_meas ib0.ideol_cum##c.long_n 1.party_control  c.jipf c.n_obs goldenshare  , vce(robust) ||paper_id:	
est store m_cl2

melogit partyeffect  1.toprest ib0.ideol_cum##c.short_n 1.party_control  c.jipf c.n_obs goldenshare  , vce(robust) ||paper_id:	
est store m_cl5
	
melogit partyeffect  1.toprest ib0.ideol_cum##c.long_n 1.party_control  c.jipf c.n_obs goldenshare  , vce(robust) ||paper_id:	
est store m_cl6

melogit partyeffect  i.gini_gr ib0.ideol_cum##c.short_n 1.party_control  c.jipf c.n_obs goldenshare  , vce(robust) ||paper_id:	
est store m_cl3
	
melogit partyeffect  i.gini_gr ib0.ideol_cum##c.long_n 1.party_control  c.jipf c.n_obs goldenshare  , vce(robust) ||paper_id:	
est store m_cl4


cd  "$RESULTSDIR"
esttab m_cl1 m_cl2 m_cl3 m_cl4 m_cl5 m_cl6  using Table_SC7.rtf, replace label compress nogaps star(* 0.10 ** 0.05 *** 0.01)  ///
se(2) b(2) aic(2) bic(2) mtitle("Model 1 (Short)" "Model 1 (long)" "Model 2 (short)" "Model 2 (long)" "Model 3 (short)" "Model 3 (long)") nobase eqlabels(none) ///
coeflabels( 1.party_control "Partisan eff.=control" 1.ideol_cum "Cumul. partisan eff." ///
 2.ineq_meas "Income ratios" 3.ineq_meas "Top income shares" ///
1.toprest_paper "Top income (ratio & share)" jipf "JIF"   goldenshare "% of Golden age" ///
 n_obs "N of observations" ib0.ideol_cum##c.long_n "Cumulative measure#Long-term channels" ///
   policies_control "policies_control" corp_control "Corporatism" short_n "Immediate channels" long_n "Long-term channels" ib0.ideol_cum##c.short_n "Cumulative measure#Short-term policies_control" controls_total "Number of policy channels" ///
postind_control "Postindustrialization" glob_control "Globalization" controls_total "Total N of channels" ///
 n_obs "N of observations"  _cons "Constant") //
 order( *goldenshare *ineq_meas *toprest *gini_gr *short_n *long_n  *ideol_cum *party_control *policies_control *corp_control *postind* *glob* )
 cd  "$DATADIR" 

*Figure S-C2: Marginal effect of policy channels on partisan effects 
gen graph_id=_n in 1/5
gen graph_x=graph_id-1

gen effect=.
gen upper=.
gen lower=.
 
 *policies_control: short
 est restore m_cl1
 margins, dydx(short_n) at(ideol_cum=0) pwcompare level(90) //-3%
 matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V
forval i=1/1 {
	local j=`i'-1
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
}
 
*policies_control: long
est restore m_cl1
 margins, dydx(short_n) at(ideol_cum=1) pwcompare level(90) //+11%
matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
}
 
*Channels: short
   est restore m_cl2
 margins, dydx(long_n) at(ideol_cum=0) pwcompare level(90) //-2%
matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'+2
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
}

*Channels: long
   est restore m_cl2
 margins, dydx(long_n) at(ideol_cum=1) pwcompare level(90) //-3%
matrix b=r(b)
matrix V=r(V)
matrix list b
matrix list V

forval i=1/1 {
	local j=`i'+3
	replace effect=b[1,`i'] 				     if graph_x==`j'
	replace upper=b[1,`i'] + 1.645*sqrt(V[`i',`i']) if graph_x==`j'
	replace lower=b[1,`i'] - 1.645*sqrt(V[`i',`i']) if graph_x==`j'
}

* twoway plot with addplot option
twoway ||  scatter effect graph_x, yaxis(1) yscale(range(0 0.3)  axis(1))   ///
		ytitle("Marginal effect on partisan effects", size(medsmall) axis(1))  ///
	    ylabel(-0.3(0.1)0.3, angle(0) nogrid) msymbol(o) ///
		xscale(range(-0.5 4.5)) ///
		xlabel( 0 "Short term" 1 "Cumulative" 3 "Short term" 4 "Cumulative", nogrid) ///
		text(0.25 0.5 "Short-term channels") ///
		text(0.25 3.5 "Long-term channels") ///
		mcolor(black)  ///
	|| rcap upper lower graph_x, yaxis(1) ///
		lcolor(black) ysize(3) xsize(4) ///
		graphregion(color(white)) xtitle("Partisan effects") ///
		legend(off) title("Long and short term effects of policy channels",size(medsmall)) ///	 xtitle("") ///
		yline(0, lpattern(dash)) name(gr2, replace) //
 
cd  "$GRAPHDIR"
graph export "Fig_SC2.png", width(3600) replace	 		
cd  "$DATADIR"
 		
 drop graph_id graph_x effect upper lower  
 
* Table S-C8: Explaining partisan effects on inequality: Effect of different data sources
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

est clear
melogit partyeffect c.goldenshare 1.party_control i.ineq_meas   1.ideol_cum controls_total  i.datasource_ineq  c.jipf c.n_obs   , vce(robust) ||paper_id:
 est store m1a

melogit partyeffect c.goldenshare toprest  1.ideol_cum 1.party_control controls_total i.datasource_ineq c.jipf c.n_obs   , vce(robust) ||paper_id: 
 est store m3a

melogit partyeffect c.goldenshare i.gini_gr  1.ideol_cum 1.party_control controls_total  i.datasource_ineq c.jipf c.n_obs   , vce(robust) ||paper_id:
 est store m2a 
 
cd  "$RESULTSDIR"
esttab m1a m2a m3a using Table_SC8.rtf, replace label  compress nogaps star(* 0.10 ** 0.05 *** 0.01)  ///
se(2) b(2) aic(2) bic(2) mtitle( "M1 (OLS)" "M1 (Logit)" "M2 (OLS)" "M2 (Logit)" "M3 (OLS)" "M3 (Logit)") nobase eqlabels(none) ///
coeflabels( 1.party_control "Partisan eff.=control" 1.ideol_cum "Cumul. partisan eff."  ///
 2.ineq_meas "Income ratios" 3.ineq_meas "Top income shares" ///
1.toprest_paper "Top income (ratio & share)" jipf "JIF"   goldenshare "% of Golden age" datasource_ineq "Data source" controls_total "Number of policy channels" ///
 n_obs "N of observations"  _cons "Constant") ///
 order( *goldenshare *ineq_meas *gini_gr *toprest  *ideol_cum *party_control controls_total *datasource_ineq ) 
 cd  "$DATADIR"
 
*Table S-C9: Summary information on different data sources for income inequality:
*Stimmt nicht mit Paper überein!

tab datasource_ineqraw, sort

cd  "$RESULTSDIR"
esttab using Table_SC9.rtf, replace ///
  noobs nonumber ///
   collabels("Obs.") ///
  nomtitle nonote label onecell nogaps //
cd  "$DATADIR"

* Table S-C10: Explaining partisan effects on inequality: Study-pooled effects

*Inequality measure
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

bysort paper_id ineq_meas : egen peff=mean(partyeffect)
bysort paper_id ineq_meas  : egen goldenshare_mean=mean(goldenshare)
bysort paper_id ineq_meas  : egen obs_mean=mean(n_obs)
bysort paper_id ineq_meas  : gen pap_c=_N
bysort paper_id ineq_meas  : egen obs_mean_ctr=mean(controls_total)

keep author year obs_mean goldenshare_mean ineq_meas gini_gr  toprest ideol_cum party_control obs_mean_ctr paper_id peff pap_c paper_id

duplicates drop paper_id ineq_meas , force
d,s //63

mixed peff goldenshare_mean pap_c i.ineq_meas ideol_cum party_control obs_mean_ctr obs_mean, vce(robust)  ||paper_id: 
est store m1

*Top vs. rest
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

bysort paper_id toprest : egen peff=mean(partyeffect)
bysort paper_id toprest  : egen goldenshare_mean=mean(goldenshare)
bysort paper_id toprest  : egen obs_mean=mean(n_obs)
bysort paper_id toprest  : gen pap_c=_N
bysort paper_id toprest  : egen obs_mean_ctr=mean(controls_total)

duplicates drop paper_id toprest , force
d,s //63

mixed peff goldenshare_mean  pap_c 1.toprest ideol_cum party_control obs_mean_ctr obs_mean, vce(robust)  ||paper_id: 
est store m3

*Gini types
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

bysort paper_id gini_gr : egen peff=mean(partyeffect)
bysort paper_id gini_gr  : egen goldenshare_mean=mean(goldenshare)
bysort paper_id gini_gr  : egen obs_mean=mean(n_obs)
bysort paper_id gini_gr  : gen pap_c=_N
bysort paper_id gini_gr  : egen obs_mean_ctr=mean(controls_total)

duplicates drop paper_id gini_gr , force
d,s //63

mixed peff goldenshare_mean pap_c ideol_cum party_control obs_mean i.gini_gr obs_mean_ctr, vce(robust)  ||paper_id: 
est store m2

cd  "$RESULTSDIR"
esttab m1 m2 m3 using Table_SC10.rtf, label replace compress nogaps star(* 0.10 ** 0.05 *** 0.01)  ///
se(2) b(2) aic(2) bic(2) mtitle( "M1 (OLS)" "M1 (Logit)" "M2 (OLS)" "M2 (Logit)" "M3 (OLS)" "M3 (Logit)") nobase eqlabels(none) ///
coeflabels( 1.party_control "Partisan eff.=control" 1.ideol_cum "Cumul. partisan eff."  ///
 2.ineq_meas "Income ratios" 3.ineq_meas "Top income shares" ///
1.toprest_paper "Top income (ratio & share)" jipf "JIF"   goldenshare_mean "% of Golden age" ///
 pap_c "Models/paper" ///
 obs_mean "N of observations"  _cons "Constant" obs_mean_ctr "Total N of policy channels") ///
 order( *goldenshare_mean *ineq_meas *gini_gr *toprest *ideol_cum *party_control controls_total)
cd  "$DATADIR"


*Table S-C11: Explaining partisan effects on inequality: Inequality vs. redistribution
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

tab ineqred ineq_meas

melogit partyeffect c.goldenshare ib0.party_control i.ineq_meas   ib0.ideol_cum  controls_total  c.jipf c.n_obs   i.ineqred, ||paper_id:
 est store m1a

melogit partyeffect c.goldenshare toprest  ib0.ideol_cum ib0.party_control controls_total c.jipf c.n_obs  i.ineqred, vce(robust) ||paper_id:
 est store m3a

melogit partyeffect c.goldenshare i.gini_gr  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs i.ineqred, vce(robust) ||paper_id:
 est store m2a 
 

melogit partyeffect c.goldenshare ib0.party_control i.ineq_meas   ib0.ideol_cum  controls_total  c.jipf c.n_obs   if ineqred==1, vce(robust) ||paper_id:
 est store m1b

melogit partyeffect c.goldenshare toprest  ib0.ideol_cum ib0.party_control controls_total c.jipf c.n_obs   if ineqred==1, vce(robust) ||paper_id:
 est store m3b

melogit partyeffect c.goldenshare i.gini_gr  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs  if ineqred==1 , vce(robust) ||paper_id: 
 est store m2b
 
melogit partyeffect c.goldenshare ib0.party_control i.ineq_meas   ib0.ideol_cum  controls_total  c.jipf c.n_obs   if ineqred==2, vce(robust) ||paper_id:
 est store m1c


 cd  "$RESULTSDIR" 
esttab m1a  m2a m3a m1b m2b m3b m1c using Table_SC11_ineqred.rtf, label replace  compress nogaps star(* 0.10 ** 0.05 *** 0.01)  ///
se(2) b(2) aic(2) bic(2) mtitle( "M1" "M2" "M3" "M4" "M5" "M6" "M7") nobase eqlabels(none) ///
coeflabels( 1.party_control "Partisan eff.=control" 1.ideol_cum "Cumul. partisan eff." ///
 2.ineq_meas "Income ratios" 3.ineq_meas "Top income shares" ///
1.toprest_paper "Top income (ratio & share)" jipf "JIF"   goldenshare "% of Golden age" ///
 controls_total "Number of policy channels" ///
 n_obs "N of observations"  _cons "Constant") ///
 order( *goldenshare *ineq_meas *gini_gr *toprest  *ideol_cum *party_control *controls_total)
cd  "$DATADIR" 

*Table S-C12: Explaining partisan effects on inequality: Controlling for measures before/after taxes and transfers 
tab prepost ineq_meas

gen gini=0
replace gini=1 if gini_gr!=.
tab gini

melogit partyeffect c.goldenshare ib0.party_control ib1.prepost i.ineq_meas i.prepost  ib0.ideol_cum  controls_total  c.jipf c.n_obs  if ineqred==1 , vce(robust) ||paper_id:
 est store m1a

melogit partyeffect c.goldenshare 1.toprest ib1.prepost  ib0.ideol_cum ib0.party_control controls_total c.jipf c.n_obs if ineqred==1, vce(robust) ||paper_id:
 est store m2a
 
melogit partyeffect c.goldenshare  ib1.prepost 1.ideol_cum 1.party_control controls_total  c.jipf c.n_obs if gini==1 & ineqred==1, vce(robust) ||paper_id:
 est store m3a 

 cd  "$RESULTSDIR" 
esttab m1a m3a m2a using Table_SC12_preposttax_control.rtf, label replace  compress nogaps star(* 0.10 ** 0.05 *** 0.01)  ///
se(2) b(2) aic(2) bic(2) mtitle( "M1" "M2" "M3") nobase eqlabels(none) ///
coeflabels( 1.party_control "Partisan eff.=control" 1.ideol_cum "Cumul. partisan eff."  ///
 2.ineq_meas "Income ratios" 3.ineq_meas "Top income shares" ///
1.toprest_paper "Top income (ratio & share)" jipf "JIF"   goldenshare "% of Golden age" ///
 1.prepost "Post-tax" controls_total "Number of policy channels" ///
 n_obs "N of observations"  _cons "Constant") ///
 order( *goldenshare *ineq_meas *toprest  *ideol_cum *party_control *controls_total *prepost)
cd  "$DATADIR"  

*Table S-C13: Explaining partisan effects on inequality: Separate models for measures before/after taxes and transfers

*pre-tax only

melogit partyeffect c.goldenshare ib0.party_control i.ineq_meas i.prepost  ib0.ideol_cum  controls_total  c.jipf c.n_obs if prepost==2, vce(robust) ||paper_id:
 est store m1a
 
melogit partyeffect c.goldenshare ib0.party_control i.ineq_meas i.prepost  ib0.ideol_cum  controls_total  c.jipf c.n_obs if prepost==1, vce(robust) ||paper_id:
 est store m1b 

melogit partyeffect c.goldenshare 1.toprest  ib0.ideol_cum ib0.party_control controls_total c.jipf c.n_obs if prepost==2, vce(robust) ||paper_id:
 est store m2a
 
*post-tax only
 
melogit partyeffect c.goldenshare 1.toprest  ib0.ideol_cum ib0.party_control controls_total c.jipf c.n_obs if prepost==1, vce(robust) ||paper_id:
 est store m2b 
 

 cd  "$RESULTSDIR" 
esttab m1a m1b m2a m2b using Table_SC13_preposttax_separate.rtf, label replace  compress nogaps star(* 0.10 ** 0.05 *** 0.01)  ///
se(2) b(2) aic(2) bic(2) mtitle( "M1 (pre)" "M1 (post)" "M2 (pre)" "M2 (post)") nobase eqlabels(none) ///
coeflabels( 1.party_control "Partisan eff.=control" 1.ideol_cum "Cumul. partisan eff."  ///
 2.ineq_meas "Income ratios" 3.ineq_meas "Top income shares" ///
1.toprest_paper "Top income (ratio & share)" jipf "JIF"   goldenshare "% of Golden age" ///
 1.prepost "Post-tax" controls_total "Number of policy channels" ///
 n_obs "N of observations"  _cons "Constant") ///
 order( *goldenshare *ineq_meas *toprest  *ideol_cum *party_control *controls_total)
cd  "$DATADIR"   
 
* Table S-C14: Explaining partisan effects on inequality: Top-income recoded (Top-1-Top10% Income Shares and Ratios vs. Rest) 
melogit partyeffect c.goldenshare ib0.party_control 1.toptop  ib0.ideol_cum  controls_total  c.jipf c.n_obs, vce(robust) ||paper_id:
 est store m1a
 
melogit partyeffect c.goldenshare ib0.party_control 1.toptop  ib0.ideol_cum  controls_total  c.jipf c.n_obs if ineq_meas>1, vce(robust) ||paper_id:
 est store m2a
 

 cd  "$RESULTSDIR" 
esttab m1a  m2a using Table_SC14_toptop.rtf, label replace  compress nogaps star(* 0.10 ** 0.05 *** 0.01)  ///
se(2) b(2) aic(2) bic(2) mtitle( "M1" "M2" "M3") nobase eqlabels(none) ///
coeflabels( 1.party_control "Partisan eff.=control" 1.ideol_cum "Cumul. partisan eff."  ///
 2.ineq_meas "Income ratios" 3.ineq_meas "Top income shares" ///
1.toprest_paper "Top income (ratio & share)" jipf "JIF"   goldenshare "% of Golden age" ///
controls_total "Number of policy channels" ///
 n_obs "N of observations"  _cons "Constant") ///
 order( *goldenshare *ineq_meas *gini_gr *toprest  *ideol_cum *party_control *controls_total)
cd  "$DATADIR"  
 
 
*Table S-C15: Explaining partisan effects on inequality: Multi-level meta regression based on available standardized coefficients 
meta meregress eff_std c.goldenshare ib0.party_control i.ineq_meas   ib0.ideol_cum  controls_total  c.jipf c.n_obs ,  ||paper_id:, essevariable(se_std) 
est store m1a

meta meregress eff_std c.goldenshare toprest  ib0.ideol_cum ib0.party_control controls_total c.jipf c.n_obs   ,  ||paper_id:, essevariable(se_std) 
est store m2a

meta meregress eff_std c.goldenshare i.gini_gr  1.ideol_cum 1.party_control controls_total c.jipf c.n_obs,  ||paper_id:, essevariable(se_std) 
est store m3a 

cd  "$RESULTSDIR" 
esttab m1a  m3a  m2a using Table_SC15_ML_meta_analysis.rtf, label replace  compress nogaps star(* 0.10 ** 0.05 *** 0.01)  ///
se(2) b(2) aic(2) bic(2) mtitle( "M1" "M2" "M3") nobase eqlabels(none) ///
coeflabels( 1.party_control "Partisan eff.=control" 1.ideol_cum "Cumul. partisan eff." ///
 2.ineq_meas "Income ratios" 3.ineq_meas "Top income shares" ///
1.toprest_paper "Top income (ratio & share)" jipf "JIF"   goldenshare "% of Golden age" ///
 controls_total "Number of policy channels" ///
 n_obs "N of observations"  _cons "Constant") ///
 order( *goldenshare *ineq_meas *gini_gr *toprest  *ideol_cum *party_control *controls_total)
cd  "$DATADIR" 
 
*Table S-C16: Explaining partisan effects on inequality: Controlling for models with/without country-fixed effects 


melogit partyeffect c.goldenshare ib0.party_control i.ineq_meas  ib0.ideol_cum  controls_total 1.country_FE c.jipf c.n_obs , vce(robust) ||paper_id:
 est store m1a

melogit partyeffect c.goldenshare toprest  ib0.ideol_cum ib0.party_control controls_total 1.country_FE c.jipf c.n_obs , vce(robust) ||paper_id:
 est store m2a
 
melogit partyeffect c.goldenshare i.gini_gr  1.ideol_cum 1.party_control controls_total 1.country_FE c.jipf c.n_obs, vce(robust) ||paper_id: 
 est store m3a 

 cd  "$RESULTSDIR" 
esttab m1a m3a m2a using Table_SC16_country_FE.rtf, label replace  compress nogaps star(* 0.10 ** 0.05 *** 0.01)  ///
se(2) b(2) aic(2) bic(2) mtitle( "M1" "M2" "M3") nobase eqlabels(none) ///
coeflabels( 1.party_control "Partisan eff.=control" 1.ideol_cum "Cumul. partisan eff." 1.country_FE "Country FE" ///
 2.ineq_meas "Income ratios" 3.ineq_meas "Top income shares" ///
1.toprest_paper "Top income (ratio & share)" jipf "JIF"   goldenshare "% of Golden age" ///
 1.country_FE "Country FE" controls_total "Number of policy channels" ///
 n_obs "N of observations"  _cons "Constant") ///
 order( *goldenshare *ineq_meas *gini_gr *toprest  *ideol_cum *party_control *controls_total)
cd  "$DATADIR" 
 
 
*Table S-C17: Explaining partisan effects on inequality: Controlling for the relationship of countries (c) divided by the time-series length 

melogit partyeffect c.goldenshare ib0.party_control i.ineq_meas  ib0.ideol_cum  controls_total twodims c.jipf c.n_obs , vce(robust) ||paper_id:
 est store m1a

melogit partyeffect c.goldenshare toprest  ib0.ideol_cum ib0.party_control controls_total twodims  c.jipf c.n_obs , vce(robust) ||paper_id:
 est store m2a
 
melogit partyeffect c.goldenshare i.gini_gr  1.ideol_cum 1.party_control controls_total twodims c.jipf c.n_obs, vce(robust) ||paper_id:
 est store m3a 

 cd  "$RESULTSDIR" 
esttab m1a m3a m2a using Table_SC17_country_nt.rtf, label replace  compress nogaps star(* 0.10 ** 0.05 *** 0.01)  ///
se(2) b(2) aic(2) bic(2) mtitle( "M1" "M2" "M3") nobase eqlabels(none) ///
coeflabels( 1.party_control "Partisan eff.=control" 1.ideol_cum "Cumul. partisan eff." twodims "Countries/Time series" ///
 2.ineq_meas "Income ratios" 3.ineq_meas "Top income shares" ///
1.toprest_paper "Top income (ratio & share)" jipf "JIF"   goldenshare "% of Golden age" ///
controls_total "Number of policy channels" ///
 n_obs "N of observations"  _cons "Constant") ///
 order( *goldenshare *ineq_meas *gini_gr *toprest  *ideol_cum *party_control *controls_total)
cd  "$DATADIR" 
 
 
****************************************
*******OUTPUT: STUDIES AND RESULTS*******
*****************************************
*Table A2: Overview of included articles

*Export data for decriptive table (overview of results)
use When_Do_Parties_Affect_Economic_Inequality_Replication.dta, clear

*Generate summary variables
bysort paper_id ineq_meas: gen c0=_n
bysort paper_id ineq_meas toprest: gen c1=_n
bysort paper_id ineq_meas toprest gini_gr: gen c2=_n

su c0 c1 c2
*pre-post-tax statistics
bysort paper_id ineq_meas toprest prepost: egen peff=mean(partyeffect)
bysort paper_id ineq_meas toprest prepost: egen goldenshare_mean=mean(goldenshare)
bysort paper_id ineq_meas toprest prepost: egen obs_mean=mean(n_obs)
bysort paper_id ineq_meas toprest prepost: gen pap_c=_N
bysort paper_id ineq_meas toprest prepost: egen obs_mean_ctr=mean(controls_total)


lab var goldenshare_mean "% share of Golden age (mean)"
lab var peff "Partisan effect (mean)"


keep author year obs_mean goldenshare_mean ineq_meas prepost  toprest ideol_cum party_control  paper_id peff pap_c

*Generate a single variable that stores author & publication year
tostring year, gen(years)
gen stud_lab=author+" ("+years+")"

list stud_lab in 1/3
drop author year*
order stud_lab obs_mean pap_c golden* ineq_meas prepost toprest ideol_cum party_control peff 

*Keep only 1 observation/paper
duplicates drop paper_id ineq_meas toprest prepost, force

*Label variables for output
lab val ideol_cum yesno_lb

lab def toprest_lb 0 "Rest" 1 "Top"
lab val toprest toprest_lb

gen peff_r=peff*100
drop peff

gen goldenshare_mean_r=goldenshare_mean*100
drop goldenshare_mean

drop paper_id

order stud_lab obs_mean pap_c goldenshare_mean_r ineq_meas prepost toprest ideol_cum party_control peff 
sort stud_lab

*Label variables for output
lab var stud_lab "Study"
lab var obs_mean "N (model)"
lab var pap_c "Results / category"
lab var goldenshare_mean_r "Golden age (%)"
lab var peff_r "Partisan effect (%)"
lab var ineq_meas "Measure of inequality"

cd  "$RESULTSDIR" 
export excel using "Table_A2.xlsx", firstrow (varlabels) replace

graph close
log close
